package ui;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import Work.Jdbc;
/*查询选项四个查询按钮*/
public class ReaderSearchButtons extends JFrame implements ActionListener {
	private JButton searchall;
	private JButton searchid;
	private JButton searchr_name;
	private JButton searchnumber;
	private JButton searchinstitute;
	private JButton returnbutton;
	//创建数据库连接类对象

    Jdbc db = new Jdbc();
	public ReaderSearchButtons() {
		JFrame jFrame = new JFrame("读者查询功能选择");
		jFrame.setLayout(new BorderLayout());
		JPanel jp1 = new JPanel(new GridLayout(3, 2, 10, 10));//设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("读者查询"));
		//this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("读者查询系统");
		setSize(300, 230);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		searchall = new JButton("查询全部读者");
		searchid = new JButton("按读者编号查询");
		searchr_name = new JButton("按读者姓名查询");
		searchnumber = new JButton("按电话查询");
		searchinstitute = new JButton("按学院查询");
		
		
		jp1.add(searchall);
		jp1.add(searchid);
		jp1.add(searchr_name);
		jp1.add(searchnumber);
		jp1.add(searchinstitute);
		getContentPane().add(jp1,BorderLayout.CENTER);

		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		JPanel jp2 = new JPanel();
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);// 把按钮放到窗口最下方
		
		searchall.addActionListener(this);
		searchid.addActionListener(this);
		searchr_name.addActionListener(this);
		searchnumber.addActionListener(this);
		searchinstitute.addActionListener(this);

		this.setVisible(true);
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		ReaderSearch1 ReaderSearch1 = new ReaderSearch1();
		if (e.getSource() == searchall) {
			this.dispose();
			ReaderSearch1.SearchAll(db);
		}else if (e.getSource() == searchr_name) {
			this.dispose();
			ReaderSearch1.Searchr_namebutton();
		}else if (e.getSource() == searchid) {
			this.dispose();
			ReaderSearch1.Searchr_idbutton();
		}else if (e.getSource() == searchnumber) {
			this.dispose();
			ReaderSearch1.Searchr_numberbutton();
		}else if (e.getSource() == searchinstitute) {
			this.dispose();
			ReaderSearch1.Searchr_institutebutton();
		}else if (e.getSource() == returnbutton) {
			this.dispose();
			new LibrarianOp();
		}  
	}
}
